package com.wus.system.controller;

import com.wus.common.core.domain.base.Result;
import com.wus.common.log.annotation.Log;
import com.wus.common.log.enums.BusinessType;
import com.wus.system.request.SysDictDataEditReq;
import com.wus.system.response.SysDictDataResp;
import com.wus.system.service.ISysDictDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 字典数据控制类
 * @Author: wus
 * @Date: 2025/1/6 15:34
 */
@Tag(name = "字典数据管理")
@Validated
@RequiredArgsConstructor
@RequestMapping("/system/dict/data")
@RestController
public class SysDictDataController {

    private final ISysDictDataService dictDataService;

    @Operation(summary = "编辑字典数据")
    @Log(title = "字典数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Result<Boolean> edit(@Validated @RequestBody SysDictDataEditReq req) {
        return Result.ok(dictDataService.edit(req));
    }

    @Operation(summary = "根据字典类型查询字典数据")
    @GetMapping("/type/{dictType}")
    public Result<List<SysDictDataResp>> getByDictType(@PathVariable("dictType") String dictType) {
        return Result.ok(dictDataService.getByDictType(dictType));
    }
}
